#include <iostream>
#include <pthread.h>
#include <string>
class Request
{
public:
    Request(const char *str, int _cnt = 0)
        : s(str), cnt(_cnt)
    {
    }
    std::string Transform(int num)
    {
        std::string str = s + "-";
        ++cnt;
        return str + std::to_string(num);
    }
public:
    std::string s;
    int cnt;
};
class Response
{
public:
    Response(int _cnt = 0)
        : cnt(_cnt)
    {
    }
public:
    int cnt;
};
void *Routine(void *arg) //新线程的启动函数
{
    Response *prs = new Response;
    Request rq(static_cast<const char *>(arg));
    std::cout << "合并线程名称:" << rq.Transform(1);
    if (rq.cnt > 0)
        prs->cnt++;
    return (void *)prs;
}
int main()
{
    pthread_t tid; // 新线程的用户级ID
    void *retval;//输出型参数
    pthread_create(&tid, nullptr, Routine, (void *)"thread");
    pthread_join(tid, &retval); // 等待新线程并且获取线程启动函数的返回值 （也可以在线程启动函数里分离线程）
    Response *ret = static_cast<Response *>(retval);
    
    if (ret->cnt > 0) // 根据新线程启动函数返回值判断该线程的任务完成情况
    {
        std::cout << "thread-1执行任务成功!" << std::endl;
    }
    delete ret;
    return 0;
}
